<?php
namespace Apipad\Controller;
use Common\Model\AreaModel;
use Think\Controller;
class PublicController extends CommonController{

	//防止表单提交token
	function getToken(){
		$token = new \Think\Token();
		$sub_token = $token->set();
		return $sub_token;
	}

	//检查token
	function checkToken($sub_token){
		$token = new \Think\Token();
		//防止重复提交
		$result = $token->check($sub_token);
		if(!$result){
			return false;
		}
		return true;
	}
 
    /**
     * 图片上传
     */
    function upfile() {
        $data = $this->upload();
        foreach($data['url'] as $key=>$val){
            $list[$key] = $this->getPicUrl($val);
        }
        $this->ajaxSucReturn($list);
    }


    public function getAreaData()
    {
        $AreaModel = M('area');
        $allData = $AreaModel->where(['level' => 1])->select();

        foreach ($allData as $pKey => $province) {
            $allData[$pKey]['children'] = $AreaModel->where(['level' => 2])->where(['pid' => $allData[$pKey]['id']])->select();
            foreach ($allData[$pKey]['children'] as $cKey => $city) {
                $allData[$pKey]['children'][$cKey]['children'] = $AreaModel->where(['level' => 3])->where(['pid' => $allData[$pKey]['children'][$cKey]['id']])->select();
            }
        }
        $result['regionData'] = $allData;
        $result['code'] = 200;
        $result['msg'] = '查询成功';
        exit(json_encode($result));
    }
 


}